package com.mzp.XbShop.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
    /**
     * 放行的接口需要自己去判断
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        // 添加拦截的请求，并排除几个不拦截的请求
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                /**
                 * excludePathPatterns 除了以下资源都不放行
                 * 改密码  注册  登陆  静态资源  放行登陆  放行 user/下的所有  未登录可以访问首页
                 *轮播图
                 */
                .excludePathPatterns("/view/changePwd", "/view/register", "/view/login","/static/**",
                        "classpath:/static/","/user/getVerify","/user/login",
                        "/user/**","**.map","/delivery/**"
                        ,"/goods/**","/userCart/**","/view/home","/goodLunbo/**",
                        "/view/goodsDetail","/pay/**","/wx_login/**","/wx_login"
                );
    }

    /**
     * 放行静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

    }
}
